<?php
/**
 * 个人会员中心   首页类
 * @author      HJC <hujianchuang@haowj.com>
 * @update      2014.06.23
 * @since       Version 1.0
 * 
 */
class IndexAction extends BaseAction 
{
    public function index()
    {
        //面试课程英语
        $user_id = $this->userInfo['id'];
        $addInfo = D('User_add')->se($user_id);
        for ($i=0;$i<$addInfo['cancel_class'];$i++)
        {
            $addInfo['cancel_arr'][$i] = $i;
        }
        $synum =  (C('PACKCLASSCANCELNUM')-$addInfo['cancel_class']);
        for ($i=0;$i<$synum;$i++)
        {
            $addInfo['cancel_sy'][$i] = $i;
        }
        $courseType = D('User_course_static')->getNowCourse($user_id,C('PACKCLASSTYPE'));
        $times = D('User_course_static')->getTimes($user_id,$courseType);
        if(!$courseType) $courseType='0';
        $course = D('new_course')->where("type=".$courseType." and status=1")->order("id desc")->find();
        $course['expiration_time'] = $times['expiration_time'];
        $course['effect_time'] = $times['effect_time'];
        $lesson = D('new_course_lesson')->where("course_id=".$course['id'])->limit($course['lesson_num'])->select();
        $course['haveon'] = 0;
        //简历完成度
        $pct = D('Practice')->where("member_id=".$user_id." and member_type=1  and practice_type=".C('PACKPRACTICE'))->sum("precentum");
        $pct = empty($pct)?"0":$pct;
        foreach ($lesson as $k=>$v)
        {
            $point = D('new_student_point')->where("user_id=".$user_id." and is_del=0 and course_number=".$v['lesson_sort']." and new_course_id=".$v['course_id'])->field('new_classroom_id,status,start_time,end_time,new_classroom_id')->find();
            if(!$point&&$times['expiration_time']>=time()) $lesson[$k]['status'] = C('PACKCLASSNO');
            if(!$point&&$times['expiration_time']<time()) $lesson[$k]['status'] = C('PACKCLASSOVERDUE');
            if($point&&is_array($point))
            {
                $lesson[$k] = array_merge($lesson[$k],$point);
                $lesson[$k]['room_num'] = D('new_classroom')->where('id='.$point['new_classroom_id'])->getField('id');
                $ppt_level =  D('new_classroom')->where('id='.$point['new_classroom_id'])->getField('ppt_level');
                if($ppt_level==2) $lesson[$k]['lesson_ppt'] = $lesson[$k]['lesson_ppt2'];
                if($point['status']==1)
                {
                    $lesson[$k]['status'] = C('PACKCLASSOVER'); //已经上过了
                    $course['haveon'] ++ ;
                } 
                if($point['status']==0&&$point['start_time']>time()+C('PACKCANCELTIME')*3600) $lesson[$k]['status'] = C('PACKCLASSCANCEL'); //已经预约了 还未开始 可以取消
                if($point['status']==0&&$point['start_time']<time()+C('PACKCANCELTIME')*3600&&$point['start_time']>=time()+C('PACKENTERCLASSROOMTIME')*60) $lesson[$k]['status'] = C('PACKCLASSNOCANCEL');//已经预约了 还未考试 不可以取消
                if($point['status']==0&&$point['start_time']<time()+C('PACKCANCELTIME')*3600&&$point['start_time']<=time()+C('PACKENTERCLASSROOMTIME')*60) $lesson[$k]['status'] = C('PACKCLASSYES');//已经预约了 可以进入教室了
                if($point['status']==0&&$point['end_time']<=time()) $lesson[$k]['status'] = C('NOENTERPACKCLASS');//翘课
                $lesson[$k]['grade_id'] = D('Grade')->where("user_id=".$user_id." and lesson_id=".$v['lesson_sort']." and type=".C('PACKCLASSTYPE'))->order("id desc")->getField("id");
            }
        }
        //求出老师修改的简历
        $tid = D('Practice')->where("member_id=".$user_id." and member_type=2 and teacher_id is not null  and practice_type=".C('PACKPRACTICE'))->order('id desc')->getField('teacher_id');
        $this->assign('tid',$tid); 
        $this->assign('packclassoverdue',C('PACKCLASSOVERDUE')); 
        $this->assign('packclassno',C('PACKCLASSNO')); 
        $this->assign('packclassyes',C('PACKCLASSYES')); 
        $this->assign('packclasscancel',C('PACKCLASSCANCEL')); 
        $this->assign('packclassnocancel',C('PACKCLASSNOCANCEL')); 
        $this->assign('packclassover',C('PACKCLASSOVER')); 
        $this->assign('noenterpackclass',C('NOENTERPACKCLASS'));
        $this->assign('course',$course);
        $this->assign('lesson',$lesson);
        $this->assign('nowtime',time());
        $this->assign('finsh',cookie($user_id.'finsh'));
        $this->assign('pct',$pct);
        $this->assign('addInfo',$addInfo);
        $this->display();
    }
    //修改会员资料
    public function editInfo()
    {
        $token = md5($this->userInfo['id'].C('HAOWJ_PRIVATE_KEY'));
        $this->assign('token',$token);
        $userInfo =  $res = $this->userInfo;
       
		$res["year"] = "";
		$res["month"] = "";
		$res["day"] = "";
		
		if($res["date_of_birth"])
		{
			$tmp = explode("-",$res["date_of_birth"]);
			$res["year"] = (integer)$tmp[0];
			$res["month"] = (integer)$tmp[1];
			$res["day"] = (integer)$tmp[2];
		}
		unset($res["password"]);
		$res["mobile"] = $res["mobile"][0].$res["mobile"][1]."******".$res["mobile"][9].$res["mobile"][10];        
        $this->assign('res',$res);
        $jsonInfo = json_encode($res);
        $this->assign('jsonInfo',$jsonInfo);
        $user_id = $userInfo["id"];
        $tmp    = md5($user_id);
        $img_src = C('WWWURL')."/static/userimg".'/'.$tmp[0]."/".$tmp[1]."/".$tmp[2]."/".$tmp[3];
        $filename162 = $img_src."/".$tmp."_big.jpg";
        $this->assign('filename162',$filename162);
        $this->display();
    }
    //提交修改资料
    public function postEditInfo()
    {
        if(!IS_AJAX) $this->ajaxReturn('','非法请求！',0); 
		$tokenid = $this->_post("tokenid");
		$user_id = $this->userInfo["id"];
		if ($tokenid != md5($user_id.C('HAOWJ_PRIVATE_KEY'))) $this->ajaxReturn('','非法请求！',0); 
			
		$data['name']         = $this->_post("name");
		$data['first_name']   = $this->_post("first_name");
		$data['last_name']    = $this->_post("last_name");
		$data['gender']       = $this->_post("gender", 1);
		$data['date_of_birth']= $this->_post("date_of_birth");
	
		$data['emergency_contact'] = $this->_post("emergency_contact");
		$data['email']             = $this->_post("email");
		$data['qq']                = $this->_post("qq");
		$data['adr_province']      = $this->_post("adr_province");
		$data['adr_city']          = $this->_post("adr_city");
		$data['corporate_name']    = $this->_post("corporate_name");
		$data['profession']        = $this->_post("profession");
	
		$nowpassword        = $this->_post("nowpssword");
		$newpassword       = $this->_post("newpassword");
	
		if($newpassword&&!$nowpassword) $this->ajaxReturn('','请填写密码！',-1);
		$password = D('user')->where("id=".$user_id)->getField('password');	
		if($newpassword&&$nowpassword&&($password!=md5($nowpassword))) $this->ajaxReturn('','原密码错误!',-1);	
		if($newpassword&&$nowpassword&&($password==md5($nowpassword))) $data['password'] = md5($newpassword);
		if(D('user')->where("id=".$user_id)->data($data)->save()) $this->ajaxReturn('','修改成功！',1);
    }
    
    //取消课程
    public  function cancelClass()
    {
        $user_id = $this->userInfo['id'];
        if(!IS_AJAX) $this->ajaxReturn('0','非法请求！',0);
        $data['new_classroom_id'] = $this->_post('new_classroom_id');
        $classroom = D('new_classroom')->where('id='.$data['new_classroom_id']." start_time>=".time()+C('PACKCANCELTIME')*3600)->getField('id');
        $lesson = D('new_student_point')->where("user_id = ".$user_id." and is_del=0 and status=0 and new_classroom_id=".$data['new_classroom_id'])->getField('id');
        if(empty($classroom)||empty($data['new_classroom_id'])||empty($lesson)) $this->ajaxReturn('0','课程已过取消时间或课程异常！',0);
        //检查取消剩余次数
        $cancel_class = D('User_add')->where("user_id=".$user_id)->getField('cancel_class');
        if($cancel_class>=C('PACKCLASSCANCELNUM')) $this->ajaxReturn('0','这位童鞋，老师已经约好，现在翘课要收跑路费哟。您已用过2次免费取消课程特权，本次要扣您50元手续费，请联系在线客服或拨打400-686-9850',0);
        $url = C('APIURL').'/api/cancelPacketclass';
        $data['user_id'] = $user_id;
        $data['cancel_flag'] = 1;
        $data['reason'] = '学生操作取消！';
        $data['sign'] = md5($data['new_classroom_id'].$data['cancel_flag'].'Haowj');
        $result = json_decode(makeRequest($url,$data,'post'),true);
        if($result['code']==1)
        {
            D('User_add')->where("user_id=".$user_id)->setInc('cancel_class',1);
            $this->ajaxReturn('1','取消成功！',1);
        } 
        if($result['code']==0) $this->ajaxReturn('0',$result['text'],0);
    }
    
    //预约课程
    public function signClass()
    {
        $user_id = $this->userInfo['id'];
    }
    //新手引导第一步
    public function stepOne()
    {
        $user_id = $this->userInfo['id'];
        if(!IS_AJAX) $this->ajaxReturn('','非法请求！',0);
        $data['first_name'] = $this->_post('first_name');
        $data['last_name'] = $this->_post('last_name');
        if(strlen($data['first_name']>30)) $this->ajaxReturn('0','请把first_name长度控制在30个字符以内！',0);
        if(strlen($data['last_name']>30)) $this->ajaxReturn('0','请把last_name长度控制在30个字符以内！',0); 
        D('user')->where("id=".$user_id)->save($data);
        $this->ajaxReturn('0','成功！',1);
    }
    //新手引导第二步
    public function stepTwo()
    {
        $user_id = $this->userInfo['id'];
        if(!IS_AJAX) $this->ajaxReturn('','非法请求！',0);
        $data['hope_industry'] = $this->_post('hangye');
        $data['hope_function'] = $this->_post('zhineng');
        if(!D('User_add')->update($user_id,$data)) $this->ajaxReturn('0','数据添加失败！',0);
        $this->ajaxReturn('0','成功！',1);
    }
    //常用英文名
    public function englishName()
    {
        $arr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
        $sex = $this->_get('gender');
        if(!$sex) $sex = '1';
        foreach($arr as $k=>$v)
        {
            $result[$v] = D('Common_name')->where("gender=".$sex." and letter='$v'")->select();
        }
        $this->assign('result',$result);
        $this->assign('sex',$sex);
        $this->assign('arr',$arr);
        $this->display();
    }
    //新版简历
    public function jianli()
    {
        
        $this->display();
    }
    public function resume()
    {
        $user_id = $this->userInfo['id'];
        $result = D('Practice')->where("member_id=".$user_id." and member_type=1  and practice_type=".C('PACKPRACTICE'))->select();
        if($result)
        {
            foreach ($result as $k=>$v)
            {
                $pct += $v['precentum'];
                $ret[$v['step']] = $v;
                $ret[$v['step']]['value'] = json_decode($v['value'],true);
                $ret[$v['step']]['count'] = count($ret[$v['step']]['value']);
            }
        }
        if(!$pct) $pct=0;
        $this->assign('pct',$pct);
        $this->assign('pctsy',100-$pct);
        $this->assign('ret',$ret);
        $title = '我的简历_好外教网'; 
        $keywords = C('SEOKEYWORDS'); 
        $description = C('SEODESCRIPTION'); 
        $seo['title']       = $title;
        $seo['keywords']    = $keywords;
        $seo['description'] = $description;
        $this->assign('seo',$seo);
        
        $this->display();
    }
    public function postResume()
    {
        $user_id = $this->userInfo['id'];
        if(!$user_id||!IS_AJAX) $this->ajaxReturn('','非法请求！',0);
        $post = $this->_post();
        $data['step'] = $post['step'];
        $data['precentum'] = $post['precentum'];
        $num = $post['num'];
        unset($post['step']);unset($post['precentum']);
        $id = D('Practice')->where("member_id=".$user_id." and member_type=1 and step=".$data['step']." and practice_type=".C('PACKPRACTICE'))->getField('id');
        if(!empty($num)) 
        {
            if($id)
            {
                $result = D('Practice')->where("id=".$id)->find();
                $value = json_decode($result['value'],true);
            }
            $value[$num] = $post;
            
            $data['value'] = json_encode($value);
        }
        else 
        {
            if($data['step']==5)
            {
                $count = count($post);
                for($i=1;$i<=($count/2);$i++)
                {
                    $ret[$i]['lang'] = $post['lang'.$i];
                    $ret[$i]['level'] = $post['level'.$i];
                }
                $post = $ret;
               
            }
            $data['value'] = json_encode($post);
        }
        $data['practice_type'] = C('PACKPRACTICE');
        $data['member_type'] = 1;
        $data['member_id'] = $user_id;
        
        if($id)
        {
            D('Practice')->where("id=".$id)->data($data)->save();
        }
        else 
        {
            $id = D('Practice')->data($data)->add();
        }
        //更新编辑次数
        D('Practice')->where("id=".$id)->setInc('edit_num',1);
        $this->ajaxReturn('','添加成功！！',1);
    }
    public function delResume()
    {
        $user_id = $this->userInfo['id'];
        if(!$user_id||!IS_AJAX) $this->ajaxReturn('','非法请求！',0);
        $post = $this->_post();
        $data['step'] = $post['step'];
       
        $num = $post['num'];
        $id = D('Practice')->where("member_id=".$user_id." and member_type=1 and step=".$data['step']." and practice_type=".C('PACKPRACTICE'))->getField('id');
       
        if($id)
        {
            $result = D('Practice')->where("id=".$id)->find();
            $value = json_decode($result['value'],true);
        }
        unset($value[$num]);
           
        $data['value'] = json_encode($value);
        if(empty($value)) D('Practice')->where("id=".$id)->delete();
        else D('Practice')->where("id=".$id)->data($data)->save();
        $this->ajaxReturn('','编辑成功！！',1);
    }
    public function  s2html()
    {
        $num = $this->_post('num');
        $step = $this->_post('step');
        $user_id = $this->userInfo['id'];
        if(!$user_id||!IS_AJAX) $this->ajaxReturn('','非法请求！',0);
        $result = D('Practice')->where("member_id=".$user_id." and member_type=1 and step=".$step." and practice_type=".C('PACKPRACTICE'))->find();
        $value = json_decode($result['value'],true);
        $ret = $value[$num];
        for($i=2014;$i>=1960;$i--)
        {
            $year .= '<li class="lieli">'.$i.'</li>';
        }
        for($j=1;$j<=12;$j++){
            $month.= '<li class="lieli">'.$j.'</li>';
        }
        
        if($ret['month1']){
            $month1=$ret['month1'];
        }else{
            $month1='month';
        }
        if($ret['month2']){
            $month2=$ret['month2'];
        }else{
            $month2='month';
        }
        if($ret['year11']){
            $year1=$ret['year11'];
        }else{
            $year1='year';
        }
        if($ret['year22']){
            $year2=$ret['year22'];
        }else{
            $year2='year';
        }
        $str3 = '<form name="form3-'.$num.'" id="form3-'.$num.'">
                    <ul>
                        <li class="box_title"><span style="float: left">School<em style="color: #ff6155">*</em></span><span style="float:left;margin-left: 20px;padding-left: 5px;" class="bg titip none">Please fill in school</span></li>
                        <li><input type="text" id="school" name="school" class="put3" value="'.$ret['school'].'"    ></li>
                        <li class="box_title">Dates Attended</li>
                        <li style="width:530px; height:30px; line-height:30px;">
                            <div class="sel" >
                                <p class="selinput" >'.$ret['year1'].'</p>
                                <p class="selicon "></p>
                                
                                <ul class="lieb" style="z-index:10">
                                    <input name="year1" value="'.$ret['year1'].'"  id="year" type="hidden" />
                                   
                                    '.$year.'
                                    
                                </ul>
                                    
                                
                            </div>
                            <div class="fleft">-</div>
                            <div class="sel" >
                                <p class="selinput" >'.$ret['year2'].'</p>
                                <p class="selicon "></p>
                                
                                <ul class="lieb" style="z-index:10">
                                    <input name="year2" value="'.$ret['year2'].'"  id="year" type="hidden" />
                                  
                                    '.$year.'
                                  
                                </ul>
                                    
                                
                            </div>
                            <div class="fleft" style="margin-left:5px; display:inline;">Or expected graduation year</div>
                        </li>
                        <li class="box_title">Degree<em style="color: #ff6155">*</em></li>
                        <li >
                            <div style="width:500px;height:30px;">
                            <div class="sel"  >
                                    <p class="selinput" >'.$ret['degree'].'</p>
                                    <p class="selicon "></p>
                                    
                                    <ul class="lieb" style="z-index:5">
                                        <input type="hidden" id="year"  name="degree"  value="'.$ret['degree'].'">
                                        
                                        <li class="lieli">Postdoctor</li>
                                        <li class="lieli">Doctorate</li>
                                        <li class="lieli">MBA/EMBA</li>
                                        <li class="lieli">Master</li>
                                        <li class="lieli">Bachelor</li>
                                        <li class="lieli">Junior College</li>
                                        <li class="lieli">Special School</li>
                                        <li class="lieli">Technical School</li>
                                        <li class="lieli">Senior High School</li>
                                        <li class="lieli">Junior High School</li>
                                    </ul>
                                        
                                    
                            </div>
                            </div>
                        </li>
                        <li class="box_title">Major</li>
                        <li><input type="text" id="study" name="study" class="put3" value="'.$ret['study'].'"></li>
                        <li class="box_title">Activities and Societies</li>
                        <li><textarea id="societies" name="societies" class="put3 pad_10" style="width:485px;" >'.$ret['societies'].'</textarea></li>
                        <li class="box_title">Examples: English Debate Society, voluntary organization, Chorus</li>
                        <li class="box_title">Description</li>
                        <li><textarea id="description" name="description" class="put3 pad_10"  style="width:485px;" >'.$ret['description'].'</textarea></li>
                        <li class="center"><span  style="cursor: pointer" id="pereonal" step="3" num='.$num.' ptc="25" class="bg bc"></span><span style="cursor: pointer" num='.$num.' step="3" class="bg qx fhqx"></span></li>
                    </ul>
                    </form>';
        $str4 = '<form name="form4-'.$num.'" id="form4-'.$num.'">
                            <table>
                                <tr>
                                    <td class="right">Project Name</td>
                                    <td><input type="text" name="project" class="put4" id="project" value="'.$ret['project'].'" ></td>
                                </tr>
    
                                <tr>
                                    <td class="right">Company Name<em style="color: #ff6155">*</em></td>
                                    <td><input type="text" name="company" class="put4" id="company" value="'.$ret['company'].'"></td>
                                </tr>
                                <tr>
                                    <td class="right">Position<em style="color: #ff6155">*</em></td>
                                    <td><input type="text" name="position" class="put4" id="position" value="'.$ret['position'].'"></td>
                                </tr>
                                <tr>
                                    <td class="right">Period<em style="color: #ff6155">*</em></td>
                                    <td>
                                        <div class="sell" >
                                <p class="sellinput" >'.$month1.'</p>
                                <p class="sellicon "></p>
                                
                                <ul class="llieb" style="z-index:10">
                                    <input name="month1" value="'.$ret['month1'].'"  id="year" type="hidden" style="width:50px;"/>
                                   
                                    '.$month.'
                                    
                                </ul>
                                    
                                
                            </div>
                            <div class="sell" >
                                <p class="sellinput" >'.$year1.'</p>
                                <p class="sellicon "></p>
                                
                                <ul class="llieb" style="z-index:10">
                                    <input name="year11" value="'.$ret['year1'].'"  id="year" type="hidden" style="width:50px;"/>
                                   
                                    '.$year.'
                                    
                                </ul>
                                    
                                
                            </div>
                            <div class="fleft">-</div>
                            <div class="sell"  >
                                <p class="sellinput" >'.$month2.'</p>
                                <p class="sellicon "></p>
                                
                                <ul class="llieb" style="z-index:10">
                                    <input name="month2" value="'.$ret['month2'].'"  id="year" type="hidden" />
                                  
                                    '.$month.'
                                  
                                </ul>
                                    
                                
                            </div>
                            <div class="sell" >
                                <p class="sellinput" >'.$year2.'</p>
                                <p class="sellicon "></p>
                                
                                <ul class="llieb" style="z-index:10">
                                    <input name="year22" value="'.$ret['year2'].'"  id="year" type="hidden" />
                                  
                                    '.$year.'
                                  
                                </ul>
                                    
                                
                            </div>
                                        </td>
                                </tr>
                                <tr>
                                    <td class="right" valign="top" style="padding-top: 10px;">Description<em style="color: #ff6155">*</em></td>
                                    <td><textarea name="description1" class="put4" id="description1" >'.$ret['description1'].'</textarea></td>
                                </tr>
                                <tr>
                                    <td class="right" valign="top" style="padding-top: 10px;">Responsibilities</td>
                                    <td><textarea name="responsibilities" class="put4" id="responsibilities" >'.$ret['responsibilities'].'</textarea></td>
                                </tr>
                                <tr>
                                    <td class="right" valign="top" style="padding-top: 10px;">Achievement</td>
                                    <td><textarea name="achievement" class="put4" id="achievement" >'.$ret['achievement'].'</textarea></td>
                                </tr>
                                <tr>
                                    <td colspan="2" class="center"><span  id="pereonal" num='.$num.' style="cursor: pointer" step='.$step.' ptc="25" class="bg bc"></span><span step="4" style="cursor: pointer" class="bg qx"></span></td>
                                </tr>
                            </table>
                        </form>';
        if($step==3) $info = $str3;
        if($step==4) $info = $str4;
        if($step==5) $info = $str5;
        $this->ajaxReturn('',$info,1);
    }
    public function postLang()
    {
        $num = $this->_post('anum');
        $sy = 100-$num;
        $user_id = $this->userInfo['id'];
        if(!$user_id||!IS_AJAX) $this->ajaxReturn('','非法请求！',0);
        $str = '<li style="width:530px; height:30px; line-height:30px;">
                            <div class="sel" style="width:100px;" >
                                <p class="selinput" style="width:70px;" >English</p>
                                <p class="selicon "></p>
                                
                                <ul class="lieb" style="width:100px; height:100px; z-index:'.$sy.';">
                                    <input name="lang"  value="English"  id="year" type="hidden" />
                                    
                                    <li class="lieli" >English</li>
                                    <li class="lieli" >Mandarin</li>
                                    <li class="lieli" >Cantonese</li>
                                    <li class="lieli" >Others</li>
                                </ul>
                                    
                                
                            </div>
                            <div class="fleft">-</div>
                            <div class="sel" style="width:220px">
                                <p class="selinput" style="width:190px;">Proficiency...</p>
                                <p class="selicon "></p>
                                
                                <ul class="lieb" style="width:220px; height:150px;z-index:'.$sy.';">
                                    <input name="level" value="Proficiency"  id="year" type="hidden" />
                                    
                                    
                                    <li class="lieli" style="width:200px;">Elementary proficiency</li>
                                    <li class="lieli" style="width:200px;">Limited working proficiency</li>
                                    <li class="lieli" style="width:200px;">Professional working proficiency</li>
                                    <li class="lieli" style="width:200px;">Full professional proficiency</li>
                                    <li class="lieli" style="width:200px;">Native or bilingual proficiency</li>
                                </ul>
                                    
                                
                            </div>
                            <div class="fleft bg dellang" style="background-position:-320px -40px; width:30px; height:30px; margin-top:2px; margin-left:3px; display:inline; cursor:pointer;"></div>
                        </li>';
        $this->ajaxReturn('',$str,1);
    }
    public function preview(){
        $user_id = $this->userInfo['id'];
        $tid = $this->_get('tid');
        if($tid) $addsql = " and member_type=2 and teacher_id=".$tid;
        else $addsql = " and member_type=1 ";
        $result = D('Practice')->where("member_id=".$user_id.$addsql."  and practice_type=".C('PACKPRACTICE'))->select();
        if($result)
        {
            foreach ($result as $k=>$v)
            {
                $pct += $v['precentum'];
                $ret[$v['step']] = $v;
                $ret[$v['step']]['value'] = json_decode($v['value'],true);
                $ret[$v['step']]['count'] = count($ret[$v['step']]['value']);
            }
        }
        if(!$pct) $pct=0;
        $title = '我的简历_好外教网'; 
        $keywords = C('SEOKEYWORDS'); 
        $description = C('SEODESCRIPTION'); 
        $seo['title']       = $title;
        $seo['keywords']    = $keywords;
        $seo['description'] = $description;
        $this->assign('seo',$seo);
        $this->assign('tid',$tid);
        $this->assign('pct',$pct);
        $this->assign('pctsy',100-$pct);
        $this->assign('ret',$ret);
        $this->display();
    }
    //下载
    public function yulan()
    {
        header('Content-type: application/msword');
        //下载显示的名字
        header('Content-Disposition: attachment; filename="简历.docx"'); 
        $path = APP_PATH.'Public/upload/10002.docx'; 
        $user_id = $this->userInfo['id'];
        $tid = $this->_get('tid');
        $url = C('APPURL').U('/Index/printHtml').'?id='.$user_id.'&tid='.$tid;
        $str = file_get_contents($url);
        echo $str;
        
        die();
        
       
    }
    
    public function printHtml(){
        //下载显示的名字
        $user_id = $this->userInfo['id'];
        $tid = $this->_get('tid');
        if($tid) $addsql = " and member_type=2 and teacher_id=".$tid;
        else $addsql = " and member_type=1 ";
        $result = D('Practice')->where("member_id=".$user_id.$addsql."  and practice_type=".C('PACKPRACTICE'))->select();
        if($result)
        {
            foreach ($result as $k=>$v)
            {
                $pct += $v['precentum'];
                $ret[$v['step']] = $v;
                $ret[$v['step']]['value'] = json_decode($v['value'],true);
                $ret[$v['step']]['count'] = count($ret[$v['step']]['value']);
            }
        }
        if(!$pct) $pct=0;
        $title = '我的简历_好外教网'; 
        $keywords = C('SEOKEYWORDS'); 
        $description = C('SEODESCRIPTION'); 
        $seo['title']       = $title;
        $seo['keywords']    = $keywords;
        $seo['description'] = $description;
        $this->assign('seo',$seo);
        $this->assign('tid',$tid);
        $this->assign('pct',$pct);
        $this->assign('pctsy',100-$pct);
        $this->assign('ret',$ret);
        $this->display();
    }
    
    public function finsh()
    {
        if(!IS_AJAX) RETURN false;
        $user_id = $this->userInfo['id'];
        if(!$user_id) return false;
        cookie($user_id.'finsh','1',3600*24*31);
        print_r($_COOKIE);
    }
    
    public function finshover()
    {
        if(!IS_AJAX) RETURN false;
        $user_id = $this->userInfo['id'];
        if(!$user_id) return false;
        cookie($user_id.'finsh',false);
    }
    //上传头像
    public function uploadFace()
    {
		$post_input = 'php://input';
		$save_path = dirname( __FILE__ );
		$postdata = file_get_contents( $post_input );
		$user_id = $this->userInfo['id'];
		$face_path = 'Public/upload/face_' . $user_id . '.jpg';
		if ( isset( $postdata ) && strlen( $postdata ) > 0 ) 
		{
		    $filename = APP_PATH.$face_path;
		    $handle = fopen( $filename, 'w+' );
		    fwrite( $handle, $postdata );
		    fclose( $handle );
		    if ( is_file( $filename ) ) 
		    {
		        $data['img'] = C('APPURL').'/'.$face_path;
		        D('User')->where("id=".$user_id)->data($data)->save();
		        echo '1';
		        exit ();
		    }else {
		        die ( 'Image upload error!' );
}
		}else {
		    die ( 'Image data not detected!' );
		}
    }
}
